﻿using System;
using System.Web;
using System.IO;

public class ExceptionHandlingModule : IHttpModule
{
    public void Init(System.Web.HttpApplication app)
    {
        app.Error += new EventHandler(OnError);
    }
 
    private void OnError(object sender, EventArgs e)
    {
        HttpApplication app = (HttpApplication)sender;
        ErrorHandler.HandleException(app.Server.GetLastError());
    }
 
    public void Dispose()
    {
        // Nothing to Dispose() }
    }

public string GetTempPath()
{
    string path = System.Environment.GetEnvironmentVariable("TEMP");
    if (!path.EndsWith("\\")) path += "\\";
    return path;
}

public void LogMessageToFile(string msg)
{
        StreamWriter sw = File.AppendText(
        GetTempPath() + "My Log File.txt");
    try
    {
        string logLine = System.String.Format(
            "{0:G}: {1}.", System.DateTime.Now, msg);
        sw.WriteLine(logLine);
    }
    finally
    {
        sw.Close();
    }
}
}